package com.xiaotu.strategy.improve;

/**
 * @author 张晓
 * @create 2020-06-27 16:18
 */
public abstract class Duck {

    //属性，策略接口
    FlyBehavior flyBehavior;
    //属性，策略接口
    QuackBehavior quackBehavior;

    //显示鸭子的信息
    public abstract void display();

    public void quack(){
        System.out.println("鸭子嘎嘎叫~~");
    }
    public void swim(){
        System.out.println("鸭子会游泳~~");
    }
    public void fly(){
        //改进
        if (flyBehavior != null) {
            flyBehavior.fly();
        }
    }

    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
    }

    public void setFlyBehavior(QuackBehavior quackBehavior) {
        this.quackBehavior = quackBehavior;
    }
}
